define([
        'core',
        'list',
        'echarts',
        'echartsTheme'
    ], function (core, list, echarts, theme) {
        var as = {};
        //饼图
        as.pie = function () {
            var pie = echarts.init(document.getElementById('appStatePieChart'));
            $.ajax({
                    url: core.getUrl("/app/statistics/rest/appStatePieData"),
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        var title = JSON.parse(data.title);
                        var dd = JSON.parse(data.data);
                        var option = {
                            title: {
                                text: '应用发布情况',
                                subtext: '',
                                x: 'center'
                            },
                            tooltip: {
                                trigger: 'item',
                                formatter: "{a} <br/>{b} : {c} ({d}%)"
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left',
                                data: title
                            },
                            series: [
                                {
                                    name: '访问来源',
                                    type: 'pie',
                                    radius: '55%',
                                    center: ['50%', '60%'],
                                    data: dd,
                                    itemStyle: {
                                        emphasis: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };
                        pie.setOption(option);
                    }
                }
            )
        };

        //线图
        as.line = function (target, url, title, unit) {
            $.ajax({
                url: url,
                success: function (dd) {
                    var jd = JSON.parse(dd);
                    var option = {
                        tooltip: {
                            trigger: 'axis',
                            position: function (pt) {
                                return [pt[0], '10%'];
                            }
                        },
                        title: {
                            left: 'center',
                            text: title,
                        },
                        legend: {
                            top: 'bottom',
                            data: ['bottom']
                        },
                        toolbox: {
                            feature: {
                                dataZoom: {
                                    yAxisIndex: 'none'
                                },
                                restore: {},
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: jd.time
                        },
                        yAxis: {
                            type: 'value',
                            minInterval: 10,
                            boundaryGap: [0, '100%']
                        },
                        dataZoom: [{
                            type: 'inside',
                            start: 0,
                            end: 100
                        }, {
                            start: 0,
                            end: 100,
                            handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                            handleSize: '80%',
                            handleStyle: {
                                color: '#fff',
                                shadowBlur: 3,
                                shadowColor: 'rgba(0, 0, 0, 0.6)',
                                shadowOffsetX: 2,
                                shadowOffsetY: 2
                            }
                        }],
                        series: [
                            {
                                name: unit,
                                type: 'line',
                                smooth: true,
                                symbol: 'none',
                                sampling: 'average',
                                itemStyle: {
                                    normal: {
                                        color: 'rgb(255, 70, 131)'
                                    }
                                },
                                areaStyle: {
                                    normal: {
                                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                            offset: 0,
                                            color: 'rgb(255, 158, 68)'
                                        }, {
                                            offset: 1,
                                            color: 'rgb(255, 70, 131)'
                                        }])
                                    }
                                },
                                data: jd.data
                            }
                        ]
                    };


                    var myChart = echarts.init(document.getElementById(target), 'Appstore');
                    myChart.setOption(option);
                }
            });
        };

        //调用量趋势图
        as.callDataSizeLine = function (target, id) {
            as.line(target, core.getUrl("/app/statistics/rest/appCallDataSizeLineData/" + id)
                , "应用调用量(KB)趋势图", "调用量(KB)");
        };
        //调用次数趋势图
        as.callTimesLine = function (target, id) {
            as.line(target, core.getUrl("/app/statistics/rest/appCallTimesLineData/" + id)
                , "应用调用次数趋势图", "调用次数");
        };

        //柱状图
        as.callTimesTotalBar = function (target, url) {
            $.ajax({
                url: url,
                success: function (data) {
                    var jsonData = JSON.parse(data);
                    var bar = echarts.init(document.getElementById(target));
                    bar.title = '应用调用次数统计';
                    var option = {
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                            }
                        },
                        legend: {
                            data: [{
                                name: '成功',
                            }, {
                                name: '失败',
                            }]
                        },
                        color: ["#0d9dff", "#c82a20"],
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value',
                            minInterval: 10
                        },
                        yAxis: {
                            type: 'category',
                            data: jsonData.title
                        },
                        series: [
                            {
                                name: '成功',
                                type: 'bar',
                                stack: '总量',
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'insideRight'
                                    }
                                },
                                data: jsonData.success
                            },
                            {
                                name: '失败',
                                type: 'bar',
                                stack: '总量',
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'insideRight'
                                    }
                                },
                                data: jsonData.fail
                            }
                        ]
                    };
                    bar.setOption(option);
                }
            });
        };

        return as;
    }
);